/**
 * 
 */
package com.wodsy.phoenix.dataservice.cms.service.impl;

import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.List;

import org.apache.commons.beanutils.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

import com.alibaba.dubbo.config.annotation.Service;
import com.alibaba.dubbo.container.Main;
import com.wodsy.phoenix.datadao.base.IBaseDao;
import com.wodsy.phoenix.datadao.cms.dao.CmsHomePageHotGoodsDao;
import com.wodsy.phoenix.dataobject.base.Pager;
import com.wodsy.phoenix.dataobject.cms.constants.HomePageObjectType;
import com.wodsy.phoenix.dataobject.cms.model.IdxHotGoodsRecommended;
import com.wodsy.phoenix.dataobject.cms.vo.IdxHotGoodsRecResp;
import com.wodsy.phoenix.dataservice.base.AbstractBaseService;
import com.wodsy.phoenix.dataservice.cms.aop.AfterOperation;
import com.wodsy.phoenix.dataservice.cms.service.CmsHomePageHotGoodsService;

/**
 * @author bryan
 *
 */
@Service(interfaceClass = CmsHomePageHotGoodsService.class, interfaceName = "com.wodsy.phoenix.dataservice.cms.service.CmsHomePageHotGoodsService")
public class CmsHomePageHotGoodsServiceImpl extends
		AbstractBaseService<IdxHotGoodsRecommended, Integer> implements
		CmsHomePageHotGoodsService {
	@Autowired
	CmsHomePageHotGoodsDao cmsHomePageHotGoodsDao;
	
	@Override
	protected IBaseDao<IdxHotGoodsRecommended, Integer> getIBaseDao() {
		return cmsHomePageHotGoodsDao;
	}
	@Transactional(readOnly=true)
	@Override
	public List<IdxHotGoodsRecResp> getOnlineHotGoodsRec() {
		List<IdxHotGoodsRecommended> list = cmsHomePageHotGoodsDao.getOnlineHotGoodsRec();
		List<IdxHotGoodsRecResp> respList = new ArrayList<IdxHotGoodsRecResp>();
		IdxHotGoodsRecResp resp = null;
		for (IdxHotGoodsRecommended hotGoods : list) {
			resp = new IdxHotGoodsRecResp();
			try {
				BeanUtils.copyProperties(resp, hotGoods);
				respList.add(resp);
			} catch (IllegalAccessException | InvocationTargetException e) {
				logger.error("object copy error!", e);
			}
		}
		return respList;
	}

	@Transactional(readOnly=true)
	@Override
	public Pager<IdxHotGoodsRecommended> searchHotGoodsRecByOrder(
			Pager<IdxHotGoodsRecommended> hotGoodsRec,
			IdxHotGoodsRecommended goodsreq) {
		return cmsHomePageHotGoodsDao.searchHotGoodsRecByOrder(hotGoodsRec, goodsreq);
	}
	@Transactional(readOnly=false)
	@Override
	public Integer updateGoodsRecommendedStatus(int goods_recId, int status) {
		return cmsHomePageHotGoodsDao.updateGoodsRecommendedStatus(goods_recId, status);
	}
	
	@Transactional(readOnly=false)
	@Override
	public Integer updateGoodsRecommendedStatus(Integer[] goods_recIds, int status) {
		return cmsHomePageHotGoodsDao.updateGoodsRecommendedStatus(goods_recIds, status);
	}
	
	@Transactional(readOnly=false)
	@AfterOperation(objectId="#hotGoods.id",objectType=HomePageObjectType.HOTGOODSRECOMMENDED,
	offlineTime="#hotGoods.offlineTime",onlineTime="#hotGoods.onlineTime" )
	@Override
	public Integer addHotGoodsRecommended(IdxHotGoodsRecommended hotGoods) {
		Integer hotId = cmsHomePageHotGoodsDao.addHotGoodsRecommended(hotGoods);
		
		return hotId;

	}
	@Transactional(readOnly=false)
	@AfterOperation(objectId="#hotGoods.id",objectType=HomePageObjectType.HOTGOODSRECOMMENDED,
	offlineTime="#hotGoods.offlineTime",onlineTime="#hotGoods.onlineTime" )
	@Override
	public void updateHotGoodsRecommended(IdxHotGoodsRecommended hotGoods) {
		cmsHomePageHotGoodsDao.updateHotGoodsRecommended(hotGoods);
	}
	public static void main(String[] args) {
		Main.main(args);
	}
}
